.upperLayer {
    position: relative;
    z-index: var(--cs-upper-layer-zindex) !important;
}

.inline-code {
    background: var(--cs-bg-color-light);
    padding: var(--cs-space-xxs) var(--cs-space-xs);
    border-radius: var(--cs-border-radius-xs);
}

.card {
    width: 100%;
    max-width: 100%;
    position: relative;
    margin-bottom: var(--cs-space-md);

    /* &:last-child {
    margin-bottom: 0;
  } */

    .title {
        position: sticky;
        top: -2px;
        z-index: 10;
        font-size: var(--cs-font-size);
        font-weight: bold;
        padding: var(--cs-space) var(--cs-space-sm) var(--cs-space-sm);
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: var(--cs-bg-color);

        .icon {
            cursor: pointer;
        }
    }

    .list {
        padding: 0 var(--cs-space-sm);
        border-radius: var(--cs-border-radius);
        border: 1px solid var(--cs-border-color);
        background: var(--cs-bg-color-light);
        box-sizing: border-box;
        margin-top: var(--cs-space);

        &:nth-child(2) {
            margin-top: 0;
        }

        .title {
            background: none;
            border-bottom: 1px solid var(--cs-border-color);
            margin-left: calc(-1 * var(--cs-space));
            margin-right: calc(-1 * var(--cs-space));
            padding: var(--cs-space);
        }

        .item {
            // min-height: 50px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--cs-border-color);
            padding: var(--cs-space-sm) 0;

            &:last-child {
                border-bottom: none;
            }

            &.draggable {
                cursor: grab;
                user-select: none;
                -webkit-user-select: none;
            }

            .label,
            .value {
                display: flex;
                align-items: center;
                justify-content: center;
                gap: var(--cs-space-xs);
            }

            .label {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: flex-start;
                gap: var(--cs-space-xs);

                .label-text {
                    display: flex;
                    flex-direction: column;

                    small,
                    a.small {
                        color: var(--cs-text-color-secondary);
                        font-size: var(--cs-font-size-xxs);

                        &.important {
                            color: var(--cs-color-primary-red);
                            font-size: var(--cs-font-size-xs);
                        }
                    }
                }
            }

            .value {
                .icon {
                    cursor: pointer;
                    padding: var(--cs-space-xs);
                    border-radius: var(--cs-border-radius);

                    &:last-child {
                        margin-right: 0;
                    }

                    &:hover {
                        background: var(--cs-active-bg-color);
                    }
                }
            }

            // .el-select {
            //     .el-select__wrapper {
            //         box-shadow: none;
            //     }
            // }
        }

        &.opacity {
            background: none;
            border: none;
            padding: 0;

            .item {
                border: none;
                padding: var(--cs-space-xs) var(--cs-space-sm);
                height: 26px;
            }
        }
    }

    .footer {
        display: flex;
        justify-content: space-between;
        padding: var(--cs-space) var(--cs-space-sm) var(--cs-space-sm);
    }
}

// override element-plus dropdown
.el-dropdown {
    .dropdown-text {
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        padding: var(--cs-space-xs) var(--cs-space-sm);
        box-sizing: border-box;

        &:hover {
            background-color: var(--cs-hover-bg-color);
            border-radius: var(--cs-border-radius);

            .text {
                color: var(--cs-text-color-primary);
            }
        }

        .text {
            display: inline-flex;
            gap: var(--cs-space-xs);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: 180px;
            font-size: var(--cs-font-size-sm);
            color: var(--cs-text-color-secondary);
        }

        .provider-logo-sm {
            width: 14px;
            height: 14px;
            border-radius: 14px;
        }

        .cs {
            font-size: var(--cs-font-size-xs) !important;
            color: var(--cs-text-color-secondary);
            padding-left: var(--cs-space-xs);
        }
    }
}

// overwrite element plus dropdown menu
.el-dropdown-menu {
    max-height: 300px;
    overflow-y: auto;

    .el-dropdown-menu__item {
        display: flex;
        flex-direction: column;
        min-width: 150px;
        max-width: 300px;
        width: auto;
        margin: auto var(--cs-space-xs);
        border-radius: var(--cs-border-radius-sm);

        &:not(.is-disabled).is-active {
            background-color: none;
            color: var(--cs-text-color-primary);
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;

            &::after {
                content: '';
                font-family: 'chatspeed';
                display: inline-block;
                margin-left: var(--cs-space);
            }
        }

        &:not(.is-disabled):focus,
        &:not(.is-disabled):hover {
            background-color: var(--cs-hover-bg-color);
            color: var(--cs-text-color-primary);
        }

        .item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;

            .name {
                display: flex;
                align-items: center;
                gap: var(--cs-space-sm);

                .provider-logo {
                    width: 16px;
                    height: 16px;
                    border-radius: 16px;
                }
            }

            &> :last-child.cs {
                font-size: var(--cs-font-size-xl);
                margin-left: var(--cs-space-lg);
                margin-right: 0;
            }

            .check-icon {
                font-size: var(--cs-font-size-md);
                color: var(--cs-text-color-primary);
            }
        }
    }

    .divider {
        border-top: 0.5px solid var(--cs-border-color);
        margin: var(--cs-space-xxs) var(--cs-space-md);
        height: 1px;
    }
}

.chat {
    .user-icon {
        font-size: var(--cs-font-size-xxl) !important;
        color: var(--cs-color-primary);
    }

    .content {
        width: 100%;
        box-sizing: border-box;
        padding: var(--cs-space);
        border-radius: var(--cs-border-radius-md);
        background-color: var(--cs-bg-color-light);
        font-size: var(--cs-font-size);
        color: var(--cs-text-color-primary);
        line-height: 1.8;
        word-break: break-all;

        &.chatting {
            width: auto;
        }

        code:not(.hljs) {
            background-color: var(--cs-code-bg-color);
            color: var(--cs-code-text-color);
            padding: var(--cs-space-xxs) var(--cs-space-xxs);
            margin: auto var(--cs-space-xxs);
            border-radius: var(--cs-space-xxs);
            overflow: auto;
            word-break: break-word;
        }

        pre {
            display: flex;
            flex-direction: column;
            padding: 0;
            border-radius: var(--cs-border-radius-md);
            border: 1px solid var(--cs-border-color);
            line-height: 1.5;
            font-size: var(--cs-font-size-sm);

            &.simple-text {
                border: none;
                word-break: break-word;
                white-space: pre-wrap;
                overflow-wrap: break-word;
                margin: 0;
            }

            code {
                &.hljs {
                    // background-color: var(--cs-code-block-bg-color);
                    border-radius: 0 0 var(--cs-border-radius-md) var(--cs-border-radius-md);
                    padding: var(--cs-space-sm);
                    will-change: contents;
                }
            }
        }

        h1 {
            font-size: 1.5em;
        }

        h2 {
            font-size: 1.4em;
        }

        h3 {
            font-size: 1.3em;
        }

        h4 {
            font-size: 1.2em;
        }

        h5 {
            font-size: 1.1em;
        }

        h6 {
            font-size: 1em;
        }

        hr {
            border-width: 1px 0 0 0;
            border-top: 1px solid var(--cs-border-color);
        }

        p {
            margin: 0 auto var(--cs-space);

            &:last-child {
                margin-bottom: 0;
            }
        }

        ul,
        ol {
            padding-left: var(--cs-space-md);
        }

        .table-container {
            max-width: 100%;
            overflow: auto;
            background: var(--cs-bg-color);
            border-radius: var(--cs-border-radius-md);
            border: 1px solid var(--cs-border-color);
            margin: var(--cs-space-sm) 0;
        }

        table {
            border-collapse: separate;
            border-spacing: 0;
            width: max-content;
            max-width: 1000px;
            min-width: 100%;
            overflow-x: auto;
            margin: 0;

            thead {
                display: table-header-group;
                vertical-align: middle;

                tr {

                    th,
                    td {
                        background: var(--cs-bg-color-box-title);
                        border-bottom: 1px solid var(--cs-border-color);

                        &:not(:last-child) {
                            border-right: 1px solid var(--cs-border-color);
                        }

                        &:first-child {
                            min-width: 100px;
                        }
                    }
                }
            }

            tbody {
                tr {
                    &:not(:last-child) {
                        td {
                            border-bottom: 1px solid var(--cs-border-color);
                        }
                    }
                }
            }

            th,
            td {
                padding: var(--cs-space-sm) var(--cs-space);

                &:not(:last-child) {
                    border-right: 1px solid var(--cs-border-color);
                }
            }
        }

        a {
            color: var(--cs-color-primary);
            cursor: pointer;
        }

        img {
            max-width: 100%;
        }

        .reference-link {
            color: var(--cs-text-color-primary);
            background-color: var(--cs-color-primary);
            text-decoration: none;
            cursor: pointer;
            font-size: var(--cs-font-size-sm);
            width: var(--cs-font-size-md);
            height: var(--cs-font-size-md);
            border-radius: var(--cs-font-size-md);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .svg-container {
            box-sizing: border-box;
            border: 1px solid var(--cs-border-color);
            border-radius: var(--cs-border-radius-md);

            .generating-svg {
                padding: var(--cs-space-sm) var(--cs-space);
            }

            pre {
                margin: 0;
                padding: 0;

                code:not(.hljs) {
                    border-radius: 0 0 var(--cs-border-radius-md) var(--cs-border-radius-md);
                    margin: 0;
                    padding: var(--cs-space-sm);
                }
            }

            .diagram-svg-container {
                overflow-x: auto;
            }

            svg {
                border-radius: var(--cs-border-radius-md);
            }
        }
    }

    .metadata {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        justify-content: space-between;
        padding: var(--cs-space-xxs) var(--cs-space-sm);

        .tokens {
            display: flex;
            flex-direction: row;
            align-items: center;
            font-size: var(--cs-font-size-xs);
            gap: var(--cs-space-xs);

            .item {
                display: inline-block;
                color: var(--cs-text-color-secondary);

                label {
                    margin-right: var(--cs-space-xxs);
                }
            }
        }

        .buttons {
            .cs {
                color: var(--cs-text-color-secondary);
                cursor: pointer;
                font-size: var(--cs-font-size-sm) !important;
                margin-right: var(--cs-space-xs);

                &:last-child {
                    margin-right: 0;
                }
            }
        }
    }

    .context-cleared {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        padding: var(--cs-space-sm) 0;
        margin: var(--cs-space-sm) 0;
        color: var(--el-text-color-secondary);
        font-size: var(--cs-font-size-sm);

        &::before {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            height: 1px;
            border-bottom: 1px solid var(--cs-border-color);
            z-index: 0;
        }

        label {
            background: var(--cs-bg-color);
            position: relative;
            display: inline-block;
            padding: 0 var(--cs-space-sm);
            z-index: 1;
        }
    }

    .clear-context {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--el-text-color-secondary);
        font-size: var(--cs-font-size-sm);
        background-color: var(--cs-bg-color);
        margin-bottom: var(--cs-space-md);

        &:hover {
            color: var(--el-text-color-primary);
        }
    }
}

.code-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--cs-space-sm);
    border-radius: var(--cs-border-radius-md) var(--cs-border-radius-md) 0 0;
    background-color: var(--cs-bg-color-box-title);
    font-size: var(--cs-font-size-sm);
    color: var(--cs-text-color-secondary);

    .cs {
        margin-left: 8px;
        cursor: pointer;
        font-size: var(--cs-font-size-sm) !important;

        &:hover {
            opacity: 0.8;
        }

        &::before {
            display: inline-block;
            margin-right: var(--cs-space-xxs);
            font-size: var(--cs-font-size) !important;
        }
    }
}

.chat-think,
.chat-reference {
    display: flex;
    flex-direction: column;
    font-size: var(--cs-font-size-sm);
    line-height: 1.5;
    padding: 0;
    margin-bottom: var(--cs-space);

    .chat-think-title,
    .chat-reference-title {
        padding: var(--cs-space-sm);
        border-radius: var(--cs-border-radius-md);
        background-color: var(--cs-bg-color-box-title);
        font-size: var(--cs-font-size);
        color: var(--cs-text-color-secondary);
        display: inline-flex;
        align-items: center;
        gap: var(--cs-space-xs);
        cursor: pointer;

        &::before {
            content: '\e64f';
            font-family: 'chatspeed';
            display: inline-block;
            margin-right: var(--cs-space-xxs);
            font-size: var(--cs-font-size-md) !important;
            color: var(--cs-color-primary);
        }

        span {
            flex: 1;
        }

        &::after {
            content: '\e642';
            font-family: 'chatspeed';
            font-size: var(--cs-font-size-sm);
            transition: transform 0.3s ease;
            display: inline-flex;
        }

        &.expanded::after {
            transform: rotate(180deg);
        }

        &.thinking::before {
            display: none;
        }
    }

    &.thinking {
        .chat-think-title::before {
            font-family: 'chatspeed';
            content: '\e891';
            animation: spin 1s infinite;
            display: inline-block;
        }
    }

    .think-content {
        padding: 0 var(--cs-space-sm);
        margin-top: var(--cs-space-sm);
        color: var(--cs-text-color-secondary);
        border-left: 3px solid var(--cs-border-color);
        word-break: break-all;
    }

    .chat-reference-list li {
        list-style: decimal;
        line-height: 2;
    }
}

.chat-log {
    border-left: 3px solid var(--cs-border-color);
    color: var(--cs-text-color-secondary);
    font-size: var(--cs-font-size-sm);
    padding: 0 var(--cs-space-sm);
    margin: var(--cs-space-xs) 0 var(--cs-space);
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;

    .item {
        border: none !important;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        white-space: pre-wrap;
        word-break: break-word;
        line-height: 1.5;
        margin: var(--cs-space-xs) 0;

        &::before {
            font-family: 'chatspeed';
            content: '\e64f';
            display: inline-block;
            margin-right: var(--cs-space-xxs);
        }
    }
}

.chat-plan {
    border-left: 3px solid var(--cs-border-color);
    padding: 0 var(--cs-space-sm);
    margin: var(--cs-space-xs) 0 var(--cs-space);
}

.icon-btn {
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--cs-space-xxs) var(--cs-space-xs);
    margin-right: var(--cs-space-xs);
    outline: none;

    &:focus,
    .cs {
        outline: none !important;
    }

    &:last-child {
        margin-right: 0;
    }

    &.disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    &:not(.disabled):hover {
        background-color: var(--cs-hover-bg-color);
        border-radius: var(--cs-border-radius);
    }
}

.cs {
    &.button {
        cursor: pointer;
    }

    &.disabled {
        opacity: 0.3;
        cursor: not-allowed;
    }
}

.cs-spin {
    animation: spin 1s infinite;
}

.ic-loading {
    display: inline-block;
    animation: spin 1s infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/*====================================================
 * rewrite global style
 *====================================================*/
*:focus-visible {
    outline: none !important;
}